<template>
  <div class="content">
    <div class="wrap">
      <div class="item" @click="handleHref('avatarUrl')">
        <div class="item-left">头像</div>
        <div class="item-right">
          <img
            class="right-pic avatarUrl"
            :src="
              info?.avatar_url
                ? info?.avatar_url
                : './../../../assets/img/default-pic.png'
            "
          />
          <img class="right-icon" src="./../../../assets/img/arrow-right.png" />
        </div>
      </div>
      <div class="item" @click="handleHref('nickName')">
        <div class="item-left">昵称</div>
        <div class="item-right">
          <text class="right-content">{{ info?.nick_name || '' }}</text>
          <img class="right-icon" src="./../../../assets/img/arrow-right.png" />
        </div>
      </div>
      <div class="item" @click="handleHref('realName')">
        <div class="item-left">真实姓名</div>
        <div class="item-right">
          <text class="right-content">{{ info?.real_name || '' }}</text>
          <img class="right-icon" src="./../../../assets/img/arrow-right.png" />
        </div>
      </div>
      <div class="item" @click="handleHref('age')">
        <div class="item-left">年龄</div>
        <div class="item-right">
          <text class="right-content">{{ info?.age || '' }}</text>
          <img class="right-icon" src="./../../../assets/img/arrow-right.png" />
        </div>
      </div>
    </div>
    <div class="red-txt">必填项</div>
    <div class="wrap">
      <div class="item" @click="handleHref('sex')">
        <div class="item-left">性别</div>
        <div class="item-right">
          <text class="right-content">{{
            typeof info?.gender == 'undefined'
              ? ''
              : info?.gender == 1
              ? '男'
              : '女'
          }}</text>
          <img class="right-icon" src="./../../../assets/img/arrow-right.png" />
        </div>
      </div>
      <div class="item" @click="handleHref('phone')">
        <div class="item-left">手机号</div>
        <div class="item-right">
          <div class="phone-box">
            <text class="right-content">{{ info?.mobile || '' }}</text>
            <img
              class="right-icon"
              src="./../../../assets/img/arrow-right.png"
            />
          </div>
        </div>
      </div>
      <div class="item" @click="handleHref('facePhoto')">
        <div class="item-left">上传人脸照片</div>
        <div class="item-right">
          <img
            class="right-pic"
            :src="
              info?.face_photo
                ? info?.face_photo
                : './../../../assets/img/default-pic.png'
            "
          />
          <img class="right-icon" src="./../../../assets/img/arrow-right.png" />
        </div>
      </div>
      <div class="item" @click="handleHref('healthCard')">
        <div class="item-left">上传健康证</div>
        <div class="item-right">
          <img
            class="right-pic"
            :src="
              info?.health?.image_url
                ? info?.health?.image_url
                : './../../../assets/img/default-pic.png'
            "
          />
          <img class="right-icon" src="./../../../assets/img/arrow-right.png" />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { onMounted, reactive, toRefs, ref } from 'vue'
import { postData } from '@/request/request.js'
import { useRoute, useRouter } from 'vue-router'
let router = useRouter()
let route = useRoute()
let query = route.query
localStorage.clear()
localStorage.setItem('user_id', query.user_id)
localStorage.setItem('access_token', query.access_token)
localStorage.setItem('open_id', query.open_id)
localStorage.setItem('currentPath', query.currentPath)
console.log(query.access_token)

let info = ref({})

let wxconfig = () => {
  let configUrl = 'https://ya30wxmp.hbwlife.com/myInfo/'
  let data = {
    user_id: localStorage.getItem('user_id'),
    access_token: localStorage.getItem('access_token'),
    open_id: localStorage.getItem('open_id'),
    currentPath: localStorage.getItem('currentPath'),
  }
  let pathParams = ''
  if (
    typeof data === 'object' &&
    data !== null &&
    !Array.isArray(data) &&
    Object.keys(data).length > 0
  ) {
    for (let key in data) {
      pathParams += key + '=' + data[key] + '&'
    }
    pathParams = pathParams.slice(0, pathParams.length - 1)
  }

  configUrl = configUrl + '?' + pathParams

  var url = window.location.href.split('#')[0]
  postData('/wxaccess/oa/jsapi/signature', {
    url: url,
  }).then((res) => {
    wx.config({
      beta: true,
      debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
      appId: 'wxaa5d43496694b970', // 必填，此时是公众号的id.一致
      timestamp: res.datas.timestamp, // 必填，生成签名的时间戳
      nonceStr: res.datas.noncestr, // 必填，生成签名的随机串
      signature: res.datas.signature, // 必填，签名
      jsApiList: ['chooseImage', 'previewImage'], // 必填，需要使用的JS接口列表
      openTagList: ['wx-open-launch-weapp'], // 跳转小程序时
    })
    wx.ready(function () {
      console.log('config is success')
    })
    wx.error(function (err) {
      console.log(JSON.stringify(err))
    })
  })
}

let initInfo = () => {
  postData('/user/info/get', { with_health: 1 }).then((res) => {
    info.value = res.datas
  })
}

let handleHref = (key) => {
  if (key == 'avatarUrl') {
    uni.navigateTo({
      url: '/pagesC/myInfo/avatarUrl',
    })
  } else if (key == 'nickName') {
    uni.navigateTo({
      url: '/pagesC/myInfo/nickName',
    })
  } else if (key == 'realName') {
    router.push('/realName')
  } else if (key == 'age') {
    router.push('/age')
  } else if (key == 'sex') {
    router.push('/sex')
  } else if (key == 'phone') {
    uni.navigateTo({
      url: '/pages/loginPhone/loginPhone',
    })
  } else if (key == 'facePhoto') {
    router.push('/userFacephoto')
  } else if (key == 'healthCard') {
    uni.navigateTo({
      url: '/pagesC/healthCard/healthCard',
    })
  }
}

onMounted(() => {
  wxconfig()
  initInfo()
})
</script>

<style scoped>
.content {
  width: 100%;
  height: 100vh;
  background: #f7f7f8;
}
.wrap {
  margin-top: 0.1rem;
}
.red-txt {
  color: #d52424;
  font-size: 0.16rem;
  padding-left: 0.2rem;
  padding: 0.3rem 0 0 0.2rem;
}
.item {
  width: 100%;
  height: 0.8rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.28rem;
}

.item {
  width: 100%;
  padding: 0 0.2rem;
  box-sizing: border-box;
  height: 0.5rem;
  background: #fff;
  border-bottom: 1px solid #f5f5f0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.item .item-left {
  width: 30%;
  display: flex;
  align-items: center;
  font-size: 0.14rem;
}

.item .item-right {
  flex: 1;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  font-size: 0.14rem;
}

.right-txt {
}
.right-pic {
  width: 0.3rem;
  height: 0.3rem;
}
.right-icon {
  margin-left: 0.1rem;
  width: 0.16rem;
  height: 0.16rem;
}

/* .avatarUrl {
  border-radius: 50%;
} */

.avatar-wrapper {
  padding: 0;
  width: 0.4rem;
  height: 0.7rem;
  border-radius: 8px;
}

.avatar {
  display: block;
  width: 100%;
  height: 100%;
}

.container {
  display: flex;
}

.phone-box {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.sub {
  width: 100%;
  height: auto;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 0.6rem;
}

.sub button {
  border: none;
  width: 90%;
  height: 0.7rem;
  line-height: 0.7rem;
  display: flex;
  justify-content: center;
  align-items: center;
  background: red;
  border-radius: 0.35rem;
  color: #fff;
  font-weight: 400;
}

.item-right-data {
  padding-right: 0.5rem;
}

.phone-txt {
  font-size: 0.14rem;
}
</style>
